package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleMenuService;
import com.atguigu.spzx.model.pojo.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.utils.DYLAssert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dyl
 * @version 1.0
 * @description:
 * @date 2025/1/3 18:15
 */
@RestController
@RequestMapping("/user/system/sysRoleMenu")
@CrossOrigin(allowCredentials = "true", originPatterns = "*", allowedHeaders = "*")
@Tag(name = "角色菜单管理")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    @GetMapping("/findMenuByRoleId/{id}")
    @Operation(summary = "根据角色id查询菜单")
    public Result<List<SysMenu>> findMenuByRoleId(@PathVariable("id") Long id) {
        List<SysMenu> list = sysRoleMenuService.findMenuByRoleId(id);
        return Result.ok(list);
    }

    @PostMapping("/updateRoleMenu/{id}")
    @Operation(summary = "根据角色id分配菜单")
    public Result updateMenuByRoleId(@PathVariable("id") Long id, @RequestBody List<Long> menuIds) {
        DYLAssert.notNull(id,"id为空，分配失败");
        DYLAssert.notNull(menuIds,"分配失败，ids为空");
        DYLAssert.isTrue(sysRoleMenuService.updateMenuByRoleId(id,menuIds),"修改失败");
        return Result.ok();
    }
}
